package com.thuanpq.activity;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.thuanpq.R;
import com.thuanpq.entity.BlacklistItemEntity;
import com.thuanpq.global.GlobalCons;

public class BlackListActivityAdapter extends BaseAdapter {

	private BlacklistItemEntity[] mEntities;
	private LayoutInflater mInflater;
	private Context mContext;

	public BlackListActivityAdapter(BlacklistItemEntity[] entity,
			Context context) {
		mContext = context;
		this.mEntities = entity;
		mInflater = LayoutInflater.from(mContext);
	}

	@Override
	public int getCount() {
		return mEntities.length;
	}

	@Override
	public BlacklistItemEntity getItem(int position) {
		return mEntities[position];
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {

			convertView = mInflater.inflate(R.layout.list_display_item_white,
					null);

			holder = new ViewHolder();

			convertView.setTag(holder);

		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		// Bind the data with the holder.
		holder.tvNo.setText((position + 1) + "");
		holder.tvNumber.setText(mEntities[position].get_phoneNumber());
		holder.tvCreatingDate.setText(mEntities[position].get_creatingDate());
		holder.tvLastCall.setText(mEntities[position].get_lastIncomingCall());
		holder.tvLastSMS.setText(mEntities[position].get_lastIncomingSMS());
		holder.tvLastMMS.setText(mEntities[position].get_lastIncomingMMS());

		if (mEntities[position].get_canAutoReply() == GlobalCons.OPTION_YES)
			holder.tvAutoReply.setText(mContext.getString(R.string.yes));
		else
			holder.tvAutoReply.setText(mContext.getString(R.string.no));

		return convertView;
	}

	public static class ViewHolder {
		public TextView tvNo;
		public TextView tvNumber;
		public TextView tvCreatingDate;
		public TextView tvLastCall;
		public TextView tvLastSMS;
		public TextView tvLastMMS;
		public TextView tvAutoReply;
	}
}
